<!--
 * @Descripttion: 
 * @Author: zhanyi
 * @Date: 2021-10-27 10:02:24
 * @FilePath: \wczd-mobile\src\pages\danger\danger-manager.vue
-->
<template>
  <zPaging class="_sxwh_box" :default-page-size="10" :fixed='false' height='100%' ref="paging" @query="queryList" v-model="dangerManagerData" :delay='200' :refresher-end-bounce-enabled="false">
    <div class="_box_item" v-for="(item,index) in dangerManagerData" :key="index" @click="_goInfo(item)">
      <div class="_title">
        <div class="_left">{{item.dangerName}}</div>
        <div class="_right danger-state" :class="_isTextColor(item)">{{_isDanger(item)}}</div>
      </div>
      <div class="_center">
        <div class="_center_item">
          <div class="_left">发现人</div>
          <div class="_right">{{item.findUsername}}</div>
        </div>
        <div class="_center_item">
          <div class="_left">创建时间</div>
          <div class="_right">{{item.createTime}}</div>
        </div>
        <div class="_center_item">
          <div class="_left">来源</div>
          <div class="_right">{{_setDangerSource(item)}}</div>
        </div>
        <div class="_center_item">
          <div class="_left">是否为隐患</div>
          <div class="_right">{{item.isDanger==='0'?'未确定':item.isDanger==='1'?'是隐患':'非隐患'}}</div>
        </div>
      </div>
      <div class="_footer">
        <div class="_left">
          {{_dangerName(item)}}
        </div>
        <div class="_right">
          <image class="_image_icon" src="@/static/wczd/more.png" alt="">
        </div>
      </div>
    </div>
  </zPaging>
</template>

<script>
import { dangerInfoList } from "@/api/danger";
import zPaging from '@/uni_modules/z-paging/components/z-paging/z-paging.vue'
import ZPagingMixin from '@/uni_modules/z-paging/components/z-paging/js/z-paging-mixin'
import customNomore from '@/pages/component/custom-nomore/custom-nomore.vue'

export default {
  name: 'danger-manage',
  components: { zPaging, customNomore },
  mixins: [ZPagingMixin],
  data () {
    return {
      dangerManagerData: [],
      dangerState: [],
      dangerSource: []
    }
  },
  created () {
    this.getDicts('danger_state').then((response) => {
      this.dangerState = response.data
    })
    this.getDicts('danger_source').then((response) => {
      this.dangerSource = response.data
    })
  },
  computed: {
    // 操作名称
    _dangerName: function () {
      return function (item) {
        return item.dangerState === '0' ? '点击隐患处置' : '点击查看详情'
      }
    },
    // 计算是否是隐患
    _isDanger: function () {
      return function (item) {
        for (let index = 0; index < this.dangerState.length; index++) {
          const element = this.dangerState[index];
          if (element.dictValue === item.dangerState) {
            return element.dictLabel
          }
        }
      }
    },
    // 计算隐患来源
    _setDangerSource: function () {
      return function (item) {
        for (let index = 0; index < this.dangerSource.length; index++) {
          const element = this.dangerSource[index];
          if (element.dictValue === item.dangerSource) {
            return element.dictLabel
          }
        }
      }
    },
    // 计算颜色样式
    _isTextColor: function () {
      return function (item) {
        return item.dangerState === '1' ? '_RED' : item.dangerState === '2' ? '_YELLOW' : '_ORANGE'
      }
    },
  },
  methods: {
    // z-paging 刷新页面
    reload () {
      this.$refs.paging.reload(false)
    },
    // z-paging 查询方法
    queryList (pageNo, pageSize) {
      console.log(pageNo, pageSize);
      uni.showLoading({
        title: '加载中'
      });
      dangerInfoList({ selectStatus: 1 }, { pageNum: pageNo, pageSize: pageSize }).then(res => {
        this.$refs.paging.complete(res.rows);
        uni.hideLoading();
      })
    },
    // 跳转处置详情页
    _goInfo (item) {
      uni.navigateTo({
        url: `/pages/danger/danger-manager-edit?dangerId=${item.id}`,
      })
    }
  },
}
</script>

<style scoped lang="scss">
</style>
